var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
import moment from "../../libs/moment.js";
const regeneratorRuntime = require('../../libs/runtime')
const app = getApp()
Page({
    data: {
        tabs: ["待付款", "已付款", "已关闭", "正在退款", "已退款"],
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        orderList: [],
    },
    onLoad: function() {
        var that = this;
        this.getOrderList();
        wx.getSystemInfo({
            success: function(res) {
                that.setData({
                    sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
                    sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
                });
            }
        });
    },
    async getOrderList() {
        const {
            result
        } = await wx.cloud.callFunction({
            name: 'getUserOrderList',
        })
        let orderList = result.orderList
        let orderListCollection = [
            [],
            [],
            [],
            [],
            []
        ]
        for (let i = 0; i < orderList.length; i++) {
            switch (orderList[i].status) {
                case 0:
                    orderListCollection[0].push(orderList[i]);
                    break;
                case 1:
                    orderListCollection[1].push(orderList[i]);
                    break;
                case 2:
                    orderListCollection[2].push(orderList[i]);
                    break;
                case 3:
                    orderListCollection[3].push(orderList[i]);
                    break;
                case 4:
                    orderListCollection[4].push(orderList[i]);
                    break;
            }
        }
        this.setData({
            orderList: orderListCollection
        })
    },
    tabClick: function(e) {
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: e.currentTarget.id
        });
        // this.getOrderList(parseInt(e.currentTarget.id) + 1);
    },
    onItemClick(e) {
        let item = e.currentTarget.dataset.item;
        wx.redirectTo({
            url: `/pages/pay-result/index?id=${item.out_trade_no}&roomId=${item.roomUnitId}&startDate=${item.startDate}&endDate=${item.endDate}`
        })
    }
});